﻿namespace Sitecore.ChangesTracker.Archiving
{
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using Sitecore.Data;

  public class ChangeTrackerArchiveEntry : Sitecore.Data.Archiving.ArchiveEntry
  {
    public ChangeTrackerArchiveEntry(Guid archivalId, ID itemId, ID parentId, string name, string originalLocation, DateTime archiveDate, string archivedBy, string archiveName, Database database) :
      base( archivalId,  itemId,  parentId,  name,  originalLocation,  archiveDate,  archivedBy,  archiveName,  database)
    {
      
    }

    public ChangeTrackerArchiveEntry(Sitecore.Data.Archiving.ArchiveEntry entry):
      base(entry.ArchivalId, entry.ItemId, entry.ParentId, entry.Name, entry.OriginalLocation, entry.ArchiveDate, entry.ArchivedBy, entry.ArchiveName, entry.Database)
    {
      
    }
  

    public string Templates
    {
      get
      {
        return base.OriginalLocation.Split(new char[] { ':' })[2];
      }
    }

    public new string ArchivedBy
    {
      get
      {         
        return base.ArchivedBy.Split(new char[]{'|'})[0];
      }
    }

    public string Reason
    {
     get
     {
       return base.ArchivedBy.Split(new char[] { '|' })[1];
     } 
    }

    public new string Database
    {
      get
      {
        return base.OriginalLocation.Split(new char[]
        {
          ':'  
        })[0];
      }
    }

    public  new string OriginalLocation
    {
      get
      {
        return base.OriginalLocation.Split(new char[]
        {
          ':'
        })[1];
      }
    }
    public bool IsTemplate
    {
        get
        {
            string str = base.OriginalLocation.Split(new char[]
        {
          ':'  
        })[3];
            return bool.Parse(str);
        }
    }

    public string CRC
    {
        get
        {
            string str =this.IsTemplate? base.OriginalLocation.Split(new char[]
        {
          ':'  
        })[4]:null;
            return str;
        }
    }

    public string Type
    {
        get
        {
            if (this.IsTemplate)
            {
                return "Template";
            }
            return "Item";
        }
    }
  }
}
